<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo" index="1" class="nav"></div>
    <script>
        var div = document.querySelector('div');
        //1.获取元素的属性值
        //(1)element.属性
        console.log(div.id); //demo
        //(2)element.getAttribute('属性') get得到 attribute属性
        console.log(div.getAttribute('id')); //demo
        console.log(div.getAttribute('index')); // 1

        //2.设置元素属性值
        //(1)element.属性='值'
        div.id = 'test';
        div.className = 'navs';
        //(2)element.setAttribute('属性','值')  主要针对属性值
        div.setAttribute('index', '2');
        div.setAttribute('class', 'footer'); //class 特殊 里面写的就是class 不是className

        //3.移除属性 removeAttribute(属性);
        div.removeAttribute('index');
    </script>
</body>

</html>